package com.deliveryservicesystem.model;

import java.io.Serializable;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * File Name: Product.java
 * Version:
 * Description:
 * Package: com.deliveryservicesystem.model.newpackage
 * Author: Lance
 * Date: Jun 24, 2012
 * Editor:
 */
@Entity
@Table(name = "PRODUCT")
@XmlRootElement
@NamedQueries(
{
    @NamedQuery(name = "Product.findAll", query = "SELECT p FROM Product p"),
    @NamedQuery(name = "Product.findByProductNo", query = "SELECT p FROM Product p WHERE p.productNo = :productNo"),
    @NamedQuery(name = "Product.findByProductPrice", query = "SELECT p FROM Product p WHERE p.productPrice = :productPrice"),
    @NamedQuery(name = "Product.findByProductDescription", query = "SELECT p FROM Product p WHERE p.productDescription = :productDescription")
})
public class Product implements Serializable
{

    private static final long serialVersionUID = 1L;
    @Id
    @SequenceGenerator(name = "SEQ_PRODUCT_NO", sequenceName = "SEQ_PRODUCT_NO")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_PRODUCT_NO")
    @Basic(optional = false)
    @Column(name = "PRODUCT_NO")
    private Integer productNo;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Basic(optional = false)
    @Column(name = "PRODUCT_PRICE")
    private double productPrice;
    @Column(name = "PRODUCT_DESCRIPTION")
    private String productDescription;
    @JoinColumn(name = "SUPPLIER_NO", referencedColumnName = "SUPPLIER_NO")
    @ManyToOne
    private Supplier supplierNo;
    @JoinColumn(name = "SUBSCRIPTION_NO", referencedColumnName = "SUBSCRIPTION_NO")
    @ManyToOne
    private Subscription subscriptionNo;

    public Product()
    {
    }

    public Product(Integer productNo)
    {
        this.productNo = productNo;
    }

    public Product(Integer productNo, double productPrice)
    {
        this.productNo = productNo;
        this.productPrice = productPrice;
    }

    public Integer getProductNo()
    {
        return productNo;
    }

    public void setProductNo(Integer productNo)
    {
        this.productNo = productNo;
    }

    public double getProductPrice()
    {
        return productPrice;
    }

    public void setProductPrice(double productPrice)
    {
        this.productPrice = productPrice;
    }

    public String getProductDescription()
    {
        return productDescription;
    }

    public void setProductDescription(String productDescription)
    {
        this.productDescription = productDescription;
    }

    public Supplier getSupplierNo()
    {
        return supplierNo;
    }

    public void setSupplierNo(Supplier supplierNo)
    {
        this.supplierNo = supplierNo;
    }

    public Subscription getSubscriptionNo()
    {
        return subscriptionNo;
    }

    public void setSubscriptionNo(Subscription subscriptionNo)
    {
        this.subscriptionNo = subscriptionNo;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (productNo != null ? productNo.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Product))
        {
            return false;
        }
        Product other = (Product) object;
        if ((this.productNo == null && other.productNo != null) || (this.productNo != null && !this.productNo.equals(other.productNo)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "Product Number: " + productNo
                + "\nProduct Price: " + productPrice
                + "\nProduct Description: " + productDescription
                + "\nSupplier Number: " + supplierNo.getSupplierNo()
                + "\nSubscription Number: " + subscriptionNo.getSubscriptionNo();
    }
}
